package com.df.tools.util;

import com.df.tools.handler.MsgDefinitionHandlerContainer;
import com.df.tools.msg.MsgDefinition;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
@Slf4j
@RequiredArgsConstructor
public class CodeGeneratorManager {
    private final ProtoParser protoParser;

    private final MsgDefinitionHandlerContainer handlerContainer;

    private List<MsgDefinition> msgDefinitions;

    public void collectMsgDefinition() {
        msgDefinitions = protoParser.parse();
    }

    public void handleMsgDefinition() {
        if (msgDefinitions == null || msgDefinitions.size() <= 0) {
            log.info("未收集msgDefinition或收集到的数量为0");
            return;
        }
        handlerContainer.handle(msgDefinitions);
    }

    public void start() {
        //        manager.addHandler();
        //解析proto文件，收集MsgDefinition
        this.collectMsgDefinition();
        //调用责任链，依次处理
        this.handleMsgDefinition();

    }
}
